﻿using MediatR;
using Traceability.App.Api.Application.Command.Detail.Cultivation;
using Traceability.App.ErrorCount;
using Traceability.App.InfrasIntructure;
using Traceability.App.Model.Cultivation;

namespace Traceability.App.Api.Application.Handler.Detail.Cultivation
{
    public class GetGetImmunityHandler : IRequestHandler<GetImmunityCommand, ApiResult<ImmunityModel>>
    {
        IBaseRepository<ImmunityModel> immRepo;

        public GetGetImmunityHandler(IBaseRepository<ImmunityModel> immRepo)
        {
            this.immRepo = immRepo;
        }

        public Task<ApiResult<ImmunityModel>> Handle(GetImmunityCommand request, CancellationToken cancellationToken)
        {
            ApiResult<ImmunityModel> res=new ApiResult<ImmunityModel>();
            var imms=immRepo.GetAll().Where(c=>c.Batch==request.Batch && !c.IsDeleted).ToList();
            if (imms == null)
            {
                res.Msg = "错误";
                res.Code = ApiEnum.Fail;
                return Task.FromResult(res);
            }
            res.Msg = "成功";
            res.Code = ApiEnum.Success;
            res.Data = imms;
            return Task.FromResult(res);
        }
    }
}
